package com.huaxin.dss2.data.dao;

import com.huaxin.dss2.data.bean.DataValue;
import com.huaxin.dss2.data.dao.base.BaseRDBDataDao;
import java.util.Date;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

/**
 * @author : luqing
 * @date : 2018/11/21 10:06
 */
@Component
@Slf4j
public class OracleDataDao extends BaseRDBDataDao {


    @Override
    public void init() {
        log.info("初始化Oracle数据源");
    }

    @Override
    public void save(String stationCode, List<DataValue> saveList, Date dataDate)
        throws Exception {
        try {
            this.batchUpdate(jdbcTemplate,saveList,dataDate);
        } catch (Exception e) {
            log.error("站点{} save方法执行异常",stationCode, e);
        }
        log.info("站点{}数据入库写入完毕！", stationCode);
    }

    @Override
    protected void batchUpdate(JdbcTemplate jdbcTemplate, List<DataValue> saveList, Date dataDate)
        throws Exception {
      /*  String tableName = hxDssProperties.getDataValueTableName();*/
        DataValue dataValue = saveList.get(0);
        String[] fullDataCode = dataValue.getDataCode().split("_");
        jdbcTemplate.batchUpdate(
            "INSERT INTO  datadb_" + fullDataCode[0] +"(stationCode,dataItemId,dataCode,textValue,dataDate,inputDate) VALUES(?,?,?,?,?,?)",
            super.batchPreparedStatementSetter(saveList,dataDate));
    }
}
